package com.terrytian.springboottq.util;

import org.springframework.util.StringUtils;

import java.util.Base64;

/**
 * @program: DevSpace
 * @ClassName CommonUtils
 * @description: 基本工具类
 * @author: tianqing
 * @create: 2022-11-26 19:23
 * @Version 1.0
 **/
public class CommonUtils {

    /**
     * 对象转换为base64字符串
     *
     * @param obj 对象值
     * @return base64字符串
     */
    public static String toBase64String(String obj) throws Exception {
        if (!StringUtils.hasText(obj)) {
            return null;
        }
        Base64.Encoder encoder = Base64.getEncoder();
        byte[] bytes = obj.getBytes("UTF-8");
        return encoder.encodeToString(bytes);
    }
}